package com.cmcc.aregister.cs.constant;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;


public class XmlResolve {
	// 常量，为编码格式
	public static final String ENCODING = "UTF-8";
	/**
	 * 解析银行卡支付返回结果xml数据
	 * 
	 * @param API
	 * @return
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	public static String getResultInfoApi(String data) throws Exception {
		String status = "";
		InputStream inputStream = new ByteArrayInputStream(data.getBytes());
		// 设置输入流
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(inputStream, ENCODING);
		int type = parser.getEventType();
		while (type != XmlPullParser.END_DOCUMENT) {
			String typename = parser.getName();
			switch (type) {
			// 元素开始
			case XmlPullParser.START_TAG:
				if ("merchantId".equals(typename)) {
				}else if("respCode".equals(typename)) {
					status = parser.nextText();
				}else if ("respDesc".equals(typename)) {
				}
				break;
			// 元素结束
			case XmlPullParser.END_TAG:
				break;
			}
			// 解析下一个标签
			type = parser.next();
		}
		inputStream.close();
		return status;
	}

}
